package com.zust.ysc012.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

import static com.zust.ysc012.service.TableService.alertStatus1;
import static com.zust.ysc012.service.TableService.alertStatus2;

/**
 * @Description
 * @Author Mato
 * @Date 04/07/2021 01:43
 */
@WebServlet(urlPatterns = "/agreeServlet")
public class AgreeServlet extends HttpServlet {
    @Override
    public void init() throws ServletException {
        super.init();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            System.out.println(111);
            int project_number = Integer.parseInt(req.getParameter("pro"));
            System.out.println(project_number);
            int i = Integer.parseInt(req.getParameter("i"));
            if (i == 1) {
                alertStatus1(project_number);
            } else {
                alertStatus2(project_number);
            }
            req.getRequestDispatcher("/WEB-INF/teacher/table.jsp").forward(req,resp);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
